package org.sbbs.app.license.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.sbbs.base.model.BaseObject;

@Entity
@Table( name = "t_customer_info" )
public class CustomerInfo
    extends BaseObject {
    /**
     *
     */
    private static final long serialVersionUID = -6140281237668070275L;

    @Id
    @GeneratedValue( strategy = GenerationType.AUTO )
    private Long customerInfoId;

    @Column( name = "customerName", length = 100, nullable = false )
    private String customerName;

    @Column( name = "note", length = 1000, nullable = true )
    private String note;

    @OneToMany( cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "customerInfo" )
    private Set<LicenseInfo> licenseInfoes = new HashSet<LicenseInfo>( 0 );

    public Long getCustomerInfoId() {
        return customerInfoId;
    }

    public void setCustomerInfoId( Long customerId ) {
        this.customerInfoId = customerId;
    }

    public String getCustomerName() {
        return customerName;
    }

    public void setCustomerName( String customerName ) {
        this.customerName = customerName;
    }

    public String getNote() {
        return note;
    }

    public void setNote( String note ) {
        this.note = note;
    }

    public Set<LicenseInfo> getLicenseInfoes() {
        return licenseInfoes;
    }

    public void setLicenseInfoes( Set<LicenseInfo> licenseInfoes ) {
        this.licenseInfoes = licenseInfoes;
    }

    @Override
    public String toString() {
        return "Customer [customerId=" + customerInfoId + ", customerName=" + customerName + ", note=" + note + "]";
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ( ( customerInfoId == null ) ? 0 : customerInfoId.hashCode() );
        result = prime * result + ( ( customerName == null ) ? 0 : customerName.hashCode() );
        result = prime * result + ( ( note == null ) ? 0 : note.hashCode() );
        return result;
    }

    @Override
    public boolean equals( Object obj ) {
        if ( this == obj )
            return true;
        if ( obj == null )
            return false;
        if ( getClass() != obj.getClass() )
            return false;
        CustomerInfo other = (CustomerInfo) obj;
        if ( customerInfoId == null ) {
            if ( other.customerInfoId != null )
                return false;
        }
        else if ( !customerInfoId.equals( other.customerInfoId ) )
            return false;
        if ( customerName == null ) {
            if ( other.customerName != null )
                return false;
        }
        else if ( !customerName.equals( other.customerName ) )
            return false;
        if ( note == null ) {
            if ( other.note != null )
                return false;
        }
        else if ( !note.equals( other.note ) )
            return false;
        return true;
    }
}
